import WxValidate from '../../../utils/WxValidate.js';
import http from '../../../utils/http.js';
import ocr from '../../../utils/ocr.js';

import {
  getDicts
} from '../../../utils/dict.js';

const {
  $Message
} = require('../../../component/iview/base/index');
// 基本参数
const baseParam = [{
  "text": "汽车型号全称",
  "field": "vehicleName",
  rule: {
    "required": true,
  },
  message: {
    "required": "汽车型号全称不能为空",
  }
}, {
  "text": "厂商",
  "field": "brand",
  rule: {
    "required": true,
    "maxlength": 64,
  },
  message: {
    "required": "品牌型号不能为空",
    "maxlength": "品牌型号不能超过64个字符",
  }
}, {
  "text": "厂商指导价（万元）",
  "field": "guidancePrice",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "厂商指导价不能超过16个字符",
    "number": "厂商指导价只能输入数字"
  }
}, {
  "text": "级别",
  "field": "level",
  "category": "AUTOHOME_VEHICLE_LEVEL",
  select: true,
}, {
  "text": "能源类型",
  "field": "fuelType",
  "category": "fuelType",
  select: true,
}, {
  "text": "环保标准",
  "field": "emissionStandard",
  "category": "AUTOHOME_EMISSION_STANDARD",
  select: true,
}, {
  "text": "上市时间",
  "field": "timeToMarket",
  date: true,
}, {
  "text": "纯电续航里程(公里）",
  "field": "pureElectricRange",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "纯电续航里程(公里）不能超过16个字符",
  }
}, {
  "text": "快充时间(小时）",
  "field": "fastCharge",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "快充时间不能超过16个字符",
  }
}, {
  "text": "慢充时间（小时）",
  "field": "normalCharge",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "慢充时间不能超过16个字符",
  }
}, {
  "text": "快充电量百分比(%)",
  "field": "fastChargePercentage",
}, {
  "text": "最大功率(kW)",
  "field": "maximumPower",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "最大功率不能超过16个字符",
    "number": "最大功率只能输入数字",
  }
}, {
  "text": "最大扭矩(Nm)",
  "field": "maximumTorque",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "最大扭矩不能超过16个字符",
    "number": "最大扭矩只能输入数字",
  }
}, {
  "text": "发动机",
  "field": "engineParameter",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "发动机不能超过16个字符",
  }
}, {
  "text": "变速箱",
  "field": "gearbox",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "变速箱不能超过16个字符",
  }
}, {
  "text": "最高车速(km/h)",
  "field": "topSpeed",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "最高车速不能超过16个字符",
    "number": "最高车速只能输入数字",
  }
}, {
  "text": "官方0-100km/h加速(s)",
  "field": "official01Time",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "最高车速不能超过16个字符",
    "number": "最高车速只能输入数字",
  }
}, {
  "text": "工信部综合油耗(L/100km)",
  "field": "officalFuelConsumption",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "工信部综合油耗不能超过16个字符",
    "number": "工信部综合油耗只能输入数字",
  }
}, {
  "text": "整车质保",
  "field": "qualityAssurance",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "整车质保不能超过16个字符",
  }
}, ]

// 车身
const carBody = [{
  "text": "长度(mm)",
  "field": "vehicleLength",
  rule: {
    "maxlength": 16,
    "max": 50000
  },
  message: {
    "number": "长度只能输入数字",
    "max": '长度不能超过50000mm'
  }
}, {
  "text": "宽度(mm)",
  "field": "vehicleWidth",
  rule: {
    "number": true,
    "max": 3000
  },
  message: {
    "number": "宽度只能输入数字",
    "max": '宽度不能超过3000mm'
  }
}, {
  "text": "高度(mm)",
  "field": "vehicleHeight",
  rule: {
    "number": true,
    "max": 3000
  },
  message: {
    "number": "高度只能输入数字",
    "max": '高度不能超过3000mm'
  }
}, {
  "text": "轴距(mm)",
  "field": "wheelbase",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "轴距不能超过16个字符",
    "number": "轴距只能输入数字",
  }
}, {
  "text": "前轮距(mm)",
  "field": "frontWheelWidth",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "前轮距不能超过16个字符",
    "number": "前轮距只能输入数字",
  }
}, {
  "text": "后轮距(mm)",
  "field": "backWheelWidth",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "后轮距不能超过16个字符",
    "number": "后轮距只能输入数字",
  }
}, {
  "text": "最小离地间隙(mm)",
  "field": "minGroundClearance",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "最小离地间隙不能超过16个字符",
    "number": "最小离地间隙只能输入数字",
  }
}, {
  "text": "车身结构",
  "field": "vehicleType",
  "category": "VEHICLE_EMISSION_STANDARD",
  select: true,
}, {
  "text": "车门数（个）",
  "field": "numberOfDoor",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "number": "车门数只能输入数字",
    "maxlength": "车门数不能超过16个字符",
  }
}, {
  "text": "座位数（个）",
  "field": "numberOfSeat",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "座位数不能超过16个字符",
    "number": "座位数只能输入数字",
  }
}, {
  "text": "油箱容积（L）",
  "field": "fuelTankCapacity",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "油箱容积不能超过16个字符",
    "number": "油箱容积只能输入数字",
  }
}, {
  "text": "整备质量（kg）",
  "field": "curbWeight",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "整备质量不能超过16个字符",
    "number": "整备质量只能输入数字",
  }
}];
// 发动机
const engineField = [{
  "text": "发动机型号",
  "field": "engineModel",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "发动机型号不能超过16个字符",
  }
}, {
  "text": "汽车排量（mL）",
  "field": "displacement",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "汽车排量不能超过16个字符",
    "number": "汽车排量只能输入数字",
  }
}, {
  "text": "汽车排量（L）",
  "field": "displacementL",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "汽车排量不能超过16个字符",
    "number": "汽车排量只能输入数字",
  }
}, {
  "text": "进气形式",
  "field": "airAdmission",
  "category": "airAdmission",
  select: true,
}, {
  "text": "气缸排列形式",
  "field": "cylinderArrangement",
  "category": "cylinderArrangement",
  select: true,
}, {
  "text": "气缸数（个）",
  "field": "cylinder",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "气缸数不能超过16个字符",
    "number": "气缸数只能输入数字",
  }
}, {
  "text": "每缸气门数（个）",
  "field": "airValve",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "每缸气门数不能超过16个字符",
    "number": "每缸气门数只能输入数字",
  }
}, {
  "text": "压缩比",
  "field": "compressionRatio",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "压缩比不能超过16个字符",
  }
}, {
  "text": "配气机构",
  "field": "valveTrain",
  "category": "valveTrain",
  select: true,
}, {
  "text": "缸径（mm）",
  "field": "cylinderDiameter",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "缸径不能超过16个字符",
  }
}, {
  "text": "行程（mm）",
  "field": "cylinderDistance",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "行程不能超过16个字符",
    "number": "行程只能输入数字",
  }
}, {
  "text": "最大马力（Ps）",
  "field": "maxHorsepower",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "最大马力不能超过16个字符",
    "number": "最大马力只能输入数字",
  }
}, {
  "text": "功率转速（rpm）",
  "field": "engineRPM",
  rule: {
    "maxlength": 33,
    // "number": true,
  },
  message: {
    "maxlength": "功率转速不能超过33个字符",
    // "number": "功率转速只能输入数字",
  }
}, {
  "text": "发动机特有技术",
  "field": "engineSpecificTechnology",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "发动机特有技术不能超过16个字符",
  }
}, {
  "text": "燃油标号",
  "field": "fuelGrade",
  "category": "fuelGrade",
  select: true,
}, {
  "text": "供油方式",
  "field": "fuelingMethod",
  "category": "fuelingMethod",
  select: true,
}, {
  "text": "缸盖材料",
  "field": "cylinderHead",
  "category": "cylinderHead",
  select: true,
}, {
  "text": "缸体材料",
  "field": "cylinderMaterial",
  "category": "cylinderMaterial",
  select: true,
}, {
  "text": "电机类型",
  "field": "motorType",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "电机类型不能超过16个字符",
  }
}, {
  "text": "电动机总功率(kW)",
  "field": "totalMotorPower",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "电动机总功率不能超过16个字符",
  }
}, {
  "text": "电动机总扭矩(N·m)",
  "field": "totalMotorTorque",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "电动机总扭矩不能超过16个字符",
  }
}, {
  "text": "前电动机最大功率(kW)",
  "field": "frontMotorPower",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "前电动机最大功率不能超过16个字符",
  }
}, {
  "text": "前电动机最大扭矩(N·m)",
  "field": "frontMotorTorque",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "前电动机最大扭矩不能超过16个字符",
  }
}, {
  "text": "后电动机最大功率(kW)",
  "field": "backMotorPower",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "后电动机最大功率不能超过16个字符",
  }
}, {
  "text": "后电动机最大扭矩(N·m)",
  "field": "backMotorTorque",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "后电动机最大扭矩不能超过16个字符",
  }
}, {
  "text": "系统综合功率(kW)",
  "field": "systemTotalPower",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "系统综合功率不能超过16个字符",
  }
}, {
  "text": "系统综合扭矩(N.m)",
  "field": "systemTotalTorque",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "系统综合扭矩不能超过16个字符",
  }
}, {
  "text": "驱动电机数",
  "field": "motorAmount",
  "category": "motorAmount",
  select: true,
}, {
  "text": "电机布局",
  "field": "motorLayout",
  "category": "motorLayout",
  select: true,
}, {
  "text": "电池类型",
  "field": "batteryType",
  "category": "batteryType",
  select: true
}, {
  "text": "工信部纯电续航里程(km)",
  "field": "mileageOfMIIT",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "工信部纯电续航里程不能超过16个字符",
  }
}, {
  "text": " 电池能量(kWh)",
  "field": "batteryEnergy",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "电池能量不能超过16个字符",
  }
}, {
  "text": "百公里耗电量(kWh/100km)",
  "field": "energyConsumptionOf100km",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "百公里耗电量不能超过16个字符",
  }
}, {
  "text": "电池组质保",
  "field": "batteryWarranty",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "电池组质保不能超过16个字符",
  }
}];

//变速箱
const speedField = [{
  "text": "档位个数",
  "field": "numberOfGear",
  rule: {
    "maxlength": 16,
    "number": true,
  },
  message: {
    "maxlength": "档位个数不能超过16个字符",
    "number": "档位个数只能输入数字",
  }
}, {
  "text": "变速箱类型",
  "field": "transmissionType",
  "category": "transmissionType",
  select: true
}]

// 底盘转向

const chassisFiled = [{
  "text": "驱动方式",
  "field": "drivingMethod",
  "category": "drivingMethod",
  select: true,
}, {
  "text": "四驱形式",
  "field": "fourWheelDriveType",
  "category": "fourWheelDriveType",
  select: true,
}, {
  "text": "中央差速器结构",
  "field": "centralDifferentialStructure",
  "category": "centralDifferentialStructure",
  select: true,
}, {
  "text": " 前悬架类型",
  "field": "frontSuspensionType",
  "category": "frontSuspensionType",
  // select: true,
}, {
  "text": "后悬架类型",
  "field": "rearSuspensionType",
  "category": "rearSuspensionType",
  // select: true,
}, {
  "text": "助力类型",
  "field": "boostType",
  "category": "boostType",
  select: true,
}, {
  "text": "车体结构",
  "field": "carBodystructure",
  "category": "carBodystructure",
  select: true,
}]

// 车轮制动
const wheelFiled = [{
  "text": "前制动器类型",
  "field": "frontBrakeType",
  "category": "frontBrakeType",
  select: true,
}, {
  "text": "后制动器类型",
  "field": "rearBrakeType",
  "category": "rearBrakeType",
  select: true,
}, {
  "text": "驻车制动类型",
  "field": "parkingBrakeType",
  "category": "parkingBrakeType",
  select: true,
}, {
  "text": "前胎规格",
  "field": "frontTire",
  "category": "frontTire",
  // select: true,
}, {
  "text": "后胎规格",
  "field": "rearTire",
  "category": "rearTire",
  // select: true,
}, {
  "text": "备胎规格",
  "field": "spareTire",
  "category": "spareTire",
  select: true,
}]

// 主/被动安全装备
const safeEquipFiled = [{
  "text": "主副驾驶座安全气囊",
  "field": "airBag",
  "category": "airBag",
  select: true, //可下拉
  multiple: true, //多选
}, {
  "text": "前后排侧气囊",
  "field": "sideAirbags",
  "category": "sideAirbags",
  select: true,
  multiple: true
}, {
  "text": "前后排头部气囊",
  "field": "headAirbags",
  "category": "headAirbags",
  select: true,
  multiple: true
}, {
  "text": "膝部气囊",
  "field": "kneeAirbags",
  "category": "kneeAirbags",
  select: true,
  local: true, //下拉框内容为本地数据
}, {
  "text": "后排安全带式气囊",
  "field": "backRowAirbags",
  "category": "backRowAirbags",
  select: true,
  local: true,
}, {
  "text": "后排中央安全气囊",
  "field": "backRowCenterAirbags",
  "category": "backRowCenterAirbags",
  select: true,
  local: true,
}, {
  "text": "被动行人保护",
  "field": "passivePedestrianProtection",
  "category": "passivePedestrianProtection",
  select: true,
  local: true,
}, {
  "text": "胎压监测功能",
  "field": "tirePressureMonitoring",
  "category": "tirePressureMonitoring",
  select: true,
  multiple: true
}, {
  "text": "零胎压继续行驶",
  "field": "zeroTireKeepGoing",
  "category": "zeroTireKeepGoing",
  select: true,
  local: true,
}, {
  "text": "安全带未系提醒",
  "field": "seatBeltReminder",
  "category": "seatBeltReminder",
  select: true,
}, {
  "text": "ISOFIX儿童座椅接口",
  "field": "childSeatInterfaceISOFIX",
  "category": "childSeatInterfaceISOFIX",
  select: true,
  local: true,
}, {
  "text": "ABS防抱死",
  "field": "abs",
  "category": "abs",
  select: true,
  local: true,
}, {
  "text": "制动力分配",
  "field": "ebd",
  "category": "ebd",
  select: true,
  local: true,
}, {
  "text": "刹车辅助",
  "field": "eba",
  "category": "eba",
  select: true,
  local: true,
}, {
  "text": "牵引力控制",
  "field": "asr",
  "category": "asr",
  select: true,
  local: true,
}, {
  "text": "车身稳定控制",
  "field": "esp",
  "category": "esp",
  select: true,
  local: true,
}, {
  "text": "并线辅助",
  "field": "blindSpotMonitoring",
  "category": "blindSpotMonitoring",
  select: true,
  local: true,
}, {
  "text": "车道偏离预警系统",
  "field": "ldws",
  "category": "ldws",
  select: true,
  local: true,
}, {
  "text": "车道保持辅助系统",
  "field": "lkas",
  "category": "lkas",
  select: true,
  local: true,
}, {
  "text": "道路交通标识识别",
  "field": "trafficSignRecognition",
  "category": "trafficSignRecognition",
  select: true,
  local: true,
}, {
  "text": "主动刹车/主动安全系统",
  "field": "activeBrake",
  "category": "activeBrake",
  select: true,
  local: true,
}, {
  "text": "疲劳驾驶提示",
  "field": "fatigueDrivingWarning",
  "category": "fatigueDrivingWarning",
  select: true,
  local: true,
}]

//辅助/操控配置
const assistControlField = [{
  "text": "前/后驻车雷达",
  "field": "parkingRadar",
  "category": "parkingRadar",
  select: true,
  multiple: true, //多选
}, {
  "text": "驾驶辅助影像",
  "field": "assistanceImage",
  "category": "assistanceImage",
  select: true,
  multiple: true,
}, {
  "text": "倒车车侧预警系统",
  "field": "rcta",
  "category": "rcta",
  select: true,
  local: true,
}, {
  "text": "巡航系统",
  "field": "acc",
  "category": "acc",
  select: true,
  multiple: true,
}, {
  "text": "驾驶模式切换",
  "field": "drivingMode",
  "category": "drivingMode",
  select: true,
  multiple: true
}, {
  "text": "自动泊车入位",
  "field": "automaticParking",
  "category": "automaticParking",
  select: true,
  local: true,
}, {
  "text": "发动机启停技术",
  "field": "startStop",
  "category": "startStop",
  select: true,
  local: true,
}, {
  "text": "自动驻车",
  "field": "autoHold",
  "category": "autoHold",
  select: true,
  local: true,
}, {
  "text": "上坡辅助",
  "field": "hillStartAssistControL",
  "category": "hillStartAssistControL",
  select: true,
  local: true,
}, {
  "text": "陡坡缓降",
  "field": "hillDescentControl",
  "category": "hillDescentControl",
  select: true,
  local: true,
}, {
  "text": "可变悬架功能",
  "field": "variableSuspension",
  "category": "variableSuspension",
  select: true,
  multiple: true
}, {
  "text": "空气悬挂",
  "field": "airSuspension",
  "category": "airSuspension",
  select: true,
  local: true,
}, {
  "text": "电磁感应悬架",
  "field": "eleSuspension",
  "category": "eleSuspension",
  select: true,
  local: true,
}, {
  "text": "可变转向比",
  "field": "variableRatio",
  "category": "variableRatio",
  select: true,
  local: true,
}, {
  "text": "中央差速器锁止功能",
  "field": "centralDifferentialLock",
  "category": "centralDifferentialLock",
  select: true,
  local: true,
}]

//外部/防盗配置
const outsideGuardField = [{
  "text": "天窗类型",
  "field": "sunroofType",
  "category": "sunroofType",
  select: true,
  multiple: true
}, {
  "text": "运动外观套件",
  "field": "sportLookKit",
  "category": "sportLookKit",
  select: true,
  local: true,
}, {
  "text": "轮圈材质",
  "field": "rimMaterial",
  "category": "rimMaterial",
  select: true,
  multiple: true
}, {
  "text": "电动吸合车门",
  "field": "electricSuctionDoor",
  "category": "electricSuctionDoor",
  select: true,
  // local: true,
}, {
  "text": "侧滑门形式",
  "field": "slidingDoorType",
  "category": "slidingDoorType",
  select: true,
  multiple: true
}, {
  "text": "电动后备箱",
  "field": "electricTrunk",
  "category": "electricTrunk",
  select: true,
  local: true,
}, {
  "text": "感应后备厢",
  "field": "inductionTrunk",
  "category": "inductionTrunk",
  select: true,
  local: true,
}, {
  "text": "车顶行李架",
  "field": "roofRack",
  "category": "roofRack",
  select: true,
  local: true,
}, {
  "text": "发动机电子防盗",
  "field": "engineAntiTheft",
  "category": "engineAntiTheft",
  select: true,
  local: true,
}, {
  "text": "车内中控锁",
  "field": "centralLock",
  "category": "centralLock",
  select: true,
  local: true,
}, {
  "text": "钥匙类型",
  "field": "keyType",
  "category": "keyType",
  select: true,
  multiple: true
}, {
  "text": "无钥匙启动系统",
  "field": "keylessStart",
  "category": "keylessStart",
  select: true,
  local: true,
}, {
  "text": "远程启动功能",
  "field": "remoteboot",
  "category": "remoteboot",
  select: true,
  local: true,
}, {
  "text": "电池预加热",
  "field": "batteryPreheating",
  "category": "batteryPreheating",
  select: true,
  local: true,
}]

//内部配置
const insideConfigureField = [{
  "text": "方向盘材质",
  "field": "steeringWheelMaterial",
  "category": "steeringWheelMaterial",
  select: true,
  multiple: true
}, {
  "text": "方向盘位置调节",
  "field": "steeringWheelPositionAdjust",
  "category": "steeringWheelPositionAdjust",
  select: true,
  multiple: true
}, {
  "text": "多功能方向盘",
  "field": "multifunctionWteeringWheel",
  "category": "multifunctionWteeringWheel",
  select: true,
  local: true,
}, {
  "text": "行车电脑显示屏幕",
  "field": "drivingComputerScreen",
  "category": "drivingComputerScreen",
  select: true,
  multiple: true
}, {
  "text": "全液晶仪表盘",
  "field": "fullLCDMeter",
  "category": "fullLCDMeter",
  select: true,
  local: true,
}, {
  "text": "液晶仪表尺寸",
  "field": "lcdSize",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "液晶仪表尺寸不能超过16个字符",
  }
}, {
  "text": "抬头数字显示仪",
  "field": "headUpDisplay",
  "category": "headUpDisplay",
  select: true,
  local: true,
}, {
  "text": "内置行车记录仪",
  "field": "drivingRecorder",
  "category": "drivingRecorder",
  select: true,
  local: true,
}]


//座椅配置
const seatField = [{
  "text": "座椅材质",
  "field": "materialOfSeats",
  "category": "materialOfSeats",
  select: true,
  multiple: true
}, {
  "text": "主座椅调节方式",
  "field": "mainSeatAdjustmentMode",
  "category": "mainSeatAdjustmentMode",
  select: true,
  multiple: true
}, {
  "text": "副座椅调节方式",
  "field": "secondSeatAdjustmentMode",
  "category": "secondSeatAdjustmentMode",
  select: true,
  multiple: true
}, {
  "text": "主/副驾驶座电动调节",
  "field": "electricAdjustmentSeat",
  "category": "electricAdjustmentSeat",
  select: true,
  multiple: true
}, {
  "text": "前排座椅功能",
  "field": "frontSeatFunction",
  "category": "frontSeatFunction",
  select: true,
  multiple: true
}, {
  "text": "电动座椅记忆",
  "field": "seatMemory",
  "category": "seatMemory",
  select: true,
  multiple: true
}, {
  "text": "第二排座椅调节",
  "field": "secondRowSeatAdjustment",
  "category": "secondRowSeatAdjustment",
  select: true,
  multiple: true
}, {
  "text": "后排座椅电动调节",
  "field": "rearSeatMotorAdjustment",
  "category": "rearSeatMotorAdjustment",
  select: true,
  local: true,
}, {
  "text": "后排座椅功能",
  "field": "rearSeatFunction",
  "category": "rearSeatFunction",
  select: true,
  multiple: true
}, {
  "text": "后排座椅放倒形式",
  "field": "rearSeatReclineForm",
  "category": "rearSeatReclineForm",
  select: true,
  multiple: true
}, {
  "text": "前后中央扶手",
  "field": "centerArmrest",
  "category": "centerArmrest",
  select: true,
  multiple: true
}, {
  "text": "后排杯架",
  "field": "rearCupShelf",
  "category": "rearCupShelf",
  select: true,
  local: true,
}]

//多媒体配置
const multiMediaField = [{
  "text": "中控彩色液晶屏幕",
  "field": "centralLCDScreen",
  "category": "centralLCDScreen",
  select: true,
  multiple: true
}, {
  "text": "中控液晶屏尺寸",
  "field": "centralLCDScreenSize",
  rule: {
    "maxlength": 16,
    // "number": true,
  },
  message: {
    "maxlength": "中控液晶屏尺寸不能超过16个字符",
    // "number": "中控液晶屏尺寸只能输入数字",
  }
}, {
  "text": "GPS导航系统",
  "field": "gps",
  "category": "gps",
  select: true,
  local: true,
}, {
  "text": "道路救援呼叫",
  "field": "roadRescueCall",
  "category": "roadRescueCall",
  select: true,
  local: true,
}, {
  "text": "蓝牙/车载电话",
  "field": "bluetoothPhone",
  "category": "bluetoothPhone",
  select: true,
  local: true,
}, {
  "text": "手机互联/映射",
  "field": "phoneConnection",
  "category": "phoneConnection",
  select: true,
  multiple: true
}, {
  "text": "车辆网",
  "field": "telematics",
  "category": "telematics",
  select: true,
  local: true,
}, {
  "text": "OTA升级",
  "field": "otaUpgrade",
  "category": "otaUpgrade",
  select: true,
  local: true,
}, {
  "text": "外接音源接口类型",
  "field": "externalAudioInterface",
  "category": "externalAudioInterface",
  select: true,
  multiple: true
}, {
  "text": "扬声器品牌名称",
  "field": "speakerBrand",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "扬声器品牌名称不能超过16个字符",
  }
}, {
  "text": "扬声器数量",
  "field": "numberOfSpeakers",
  rule: {
    "maxlength": 16,
  },
  message: {
    "maxlength": "扬声器数量不能超过16个字符",
  }
}]

//灯光配置
const lightingField = [{
  "text": "近光灯光源",
  "field": "lowBeamLights",
  "category": "lowBeamLights",
  select: true,
  multiple: true
}, {
  "text": "远光灯光源",
  "field": "hightBeamLights",
  "category": "hightBeamLights",
  select: true,
  multiple: true
}, {
  "text": "灯光特色功能",
  "field": "lightingFeatures",
  "category": "lightingFeatures",
  select: true,
  multiple: true
}, {
  "text": "LED日间行车灯",
  "field": "ledDaytimeLights",
  "category": "ledDaytimeLights",
  select: true,
  local: true,
}, {
  "text": "自适应远近光",
  "field": "adaptiveLight",
  "category": "adaptiveLight",
  select: true,
  local: true,
}, {
  "text": "自动头灯",
  "field": "automaticHeadlight",
  "category": "automaticHeadlight",
  select: true,
  local: true,
}, {
  "text": "转向辅助灯",
  "field": "steeringAssistLight",
  "category": "steeringAssistLight",
  select: true,
  local: true,
}, {
  "text": "大灯高度可调",
  "field": "headlightHeightAdjustable",
  "category": "headlightHeightAdjustable",
  select: true,
  local: true,
}, {
  "text": "大灯清洗装置",
  "field": "headlightCleaning",
  "category": "headlightCleaning",
  select: true,
  local: true,
}, {
  "text": "大灯延时关闭",
  "field": "delayedHeadlightShutdown",
  "category": "delayedHeadlightShutdown",
  select: true,
  local: true,
}, {
  "text": "车内环境氛围灯",
  "field": "interiorAmbientLight",
  "category": "interiorAmbientLight",
  select: true,
  multiple: true
}]

//玻璃/后视镜
const glassField = [{
  "text": "前/后电动车窗",
  "field": "powerWindows",
  "category": "powerWindows",
  select: true,
  multiple: true
}, {
  "text": "车窗一键升降功能",
  "field": "oneButtonLift",
  "category": "oneButtonLift",
  select: true,
  multiple: true
}, {
  "text": "车窗防夹手功能",
  "field": "windowAntiPinch",
  "category": "windowAntiPinch",
  select: true,
  local: true,
}, {
  "text": "外后视镜功能",
  "field": "exteriorMirrorFunction",
  "category": "exteriorMirrorFunction",
  select: true,
  multiple: true
}, {
  "text": "车内化妆镜",
  "field": "makeUpMirro",
  "category": "makeUpMirro",
  select: true,
  multiple: true
}, {
  "text": "感应雨刷",
  "field": "inductionWiper",
  "category": "inductionWiper",
  select: true,
  multiple: true
  // local: true,
}]


//空调/冰箱
const airConditionerField = [{
  "text": "空调温度控制方式",
  "field": "airConditioning",
  "category": "airConditioning",
  select: true,
  multiple: true
}, {
  "text": "后排独立空调",
  "field": "rearAirConditioner",
  "category": "rearAirConditioner",
  select: true,
  local: true,
}, {
  "text": "后座出风口",
  "field": "rearAirOutlet",
  "category": "rearAirOutlet",
  select: true,
  local: true,
}, {
  "text": "温度分区控制",
  "field": "temperatureZoneControl",
  "category": "temperatureZoneControl",
  select: true,
  local: true,
}, {
  "text": "车内PM2.5过滤装置",
  "field": "pm25",
  "category": "pm25",
  select: true,
  local: true,
}]


//基本信息
const vehicleField = [{
    "text": "登记证编号",
    "field": "registerNo",
    "scan": true,
    rule: {
      "required": false,
      "maxlength": 12,
      "minlength": 12,
      "number": true,
    },
    message: {
      "required": "登记证书编号不能为空",
      "maxlength": "登记证书编号不能超过12个字符",
      // "enNum": "登记证书编号只能是英文和数字"
      "number": "登记证书编号只能是数字"
    }
  },
  {
    "text": "车架号",
    "field": "vin",
    rule: {
      "required": true,
      "maxlength": 32,
      "enNum": true,
    },
    message: {
      "required": "车架号不能为空",
      "maxlength": "车架号不能超过32个字符",
      "enNum": '车架号只能输入英文和数字'
    }
  }, {
    "text": "车牌号码",
    "field": "plateNo",
    rule: {
      "required": true,
      "plateNo": true
    },
    message: {
      "required": "车牌号码不能为空"
    }
  }, {
    "text": "厂商",
    "field": "brand",
    rule: {
      "required": true,
      "maxlength": 64,
    },
    message: {
      "required": "品牌型号不能为空",
      "maxlength": "品牌型号不能超过64个字符",
    }
  }, {
    "text": "发动机号",
    "field": "engineNo",
    rule: {
      "required": true,
      "maxlength": 64,
      "lineEnNum": true
    },
    message: {
      "required": "发动机号不能为空",
      "maxlength": "发动机号不能超过64个字符",
      "lineEnNum": "发动机号只能是英文和数字和横杠"
    }
  }, {
    "text": "行驶证注册日期",
    "field": "registerDate",
    date: true,
  }, {
    "text": "行驶证签发日期",
    "field": "issueDate",
    date: true,
  }, {
    "text": "颜色",
    "field": "color",
    rule: {
      "maxlength": 16,
    },
    message: {
      "maxlength": "颜色不能超过16个字符",
    }
  }, {
    "text": "使用性质",
    "field": "useProperty",
    "category": "VEHICLE_USE_PROPERTY",
    select: true
  }, {
    "text": "号牌种类",
    "field": "plateType",
    "category": "VEHICLE_PLATE_TYPE",
    select: true,
  }, {
    "text": "出厂日期",
    "field": "productionDate",
    date: true,
  },
];


Page({

  /**
   * 页面的初始数据
   */
  data: {
    placeheight: 0,
    commission: null, //本次交易的费用
    show: false, //是否弹窗
    currentStep: 0,
    formField: [
      baseParam, carBody, engineField, speedField, chassisFiled, wheelFiled, safeEquipFiled,
      assistControlField, outsideGuardField, insideConfigureField, seatField, multiMediaField, lightingField, glassField,
      airConditionerField
    ],
    files: {},
    filesFlag: {},

    formDict: {
      "vehicle.isImported": [{
        code: 0,
        name: '非进口车'
      }, {
        code: 1,
        name: '进口车'
      }],
    },
    // 是否有无配置
    hasDisposeSel: [{
      code: 0,
      name: '无'
    }, {
      code: 1,
      name: '有'
    }],
    formData: {
      "vehicle.isImported": 0,
      "destination": '福建省厦门市',
    },
    formSelectData: {
      "vehicle.isImported": 0,
    },
    confirmShow: false, //用来展示是否切换个人和企业
    confirmField: '', //确定要更改的字段
    confirmValue: '', //确定要更改后的值
    srcollWidth: 0,
    files: {},
    filesFlag: {},
    hasDisposeDicts: [],
    multipleDicts: ['airBag','sideAirbags','headAirbags','tirePressureMonitoring','parkingRadar','assistanceImage','acc','drivingMode','variableSuspension','sunroofType','rimMaterial','slidingDoorType','keyType','steeringWheelMaterial','steeringWheelPositionAdjust','drivingComputerScreen','materialOfSeats',"mainSeatAdjustmentMode","secondSeatAdjustmentMode","electricAdjustmentSeat","frontSeatFunction","seatMemory","secondRowSeatAdjustment","rearSeatFunction","rearSeatReclineForm","centerArmrest","centralLCDScreen","phoneConnection","externalAudioInterface","lowBeamLights","hightBeamLights","lightingFeatures","interiorAmbientLight","powerWindows","oneButtonLift","exteriorMirrorFunction","makeUpMirro","inductionWiper","airConditioning"], // 多选字典
    selectDicts: ['level','fuelType','emissionStandard','vehicleType','airAdmission','cylinderArrangement','valveTrain','fuelGrade','fuelingMethod','cylinderHead','cylinderMaterial','motorAmount','motorLayout','batteryType','transmissionType','drivingMethod','fourWheelDriveType','centralDifferentialStructure','boostType','carBodystructure','frontBrakeType','rearBrakeType','parkingBrakeType','spareTire','seatBeltReminder','electricSuctionDoor'], // 单选字典
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let dictFieldArray = ['level','fuelType','emissionStandard','vehicleType','airAdmission','cylinderArrangement','valveTrain','fuelGrade','fuelingMethod','cylinderHead','cylinderMaterial','motorAmount','motorLayout','batteryType','transmissionType','drivingMethod','fourWheelDriveType','centralDifferentialStructure','boostType','carBodystructure','frontBrakeType','rearBrakeType','parkingBrakeType','spareTire','seatBeltReminder','electricSuctionDoor'];
    // 有无配置选项字典
    let hasDisposeDicts = ['kneeAirbags','backRowAirbags','backRowCenterAirbags','passivePedestrianProtection','zeroTireKeepGoing','childSeatInterfaceISOFIX','abs','ebd','eba','asr','esp','blindSpotMonitoring','ldws','lkas','trafficSignRecognition','activeBrake','fatigueDrivingWarning','rcta','automaticParking','startStop','autoHold','hillStartAssistControL','hillDescentControl','airSuspension','eleSuspension','variableRatio','centralDifferentialLock','sportLookKit','electricTrunk','inductionTrunk','roofRack','engineAntiTheft','centralLock','keylessStart','remoteboot','batteryPreheating','multifunctionWteeringWheel','fullLCDMeter','headUpDisplay','drivingRecorder',"rearSeatMotorAdjustment","rearCupShelf","gps","roadRescueCall","bluetoothPhone","telematics","otaUpgrade","ledDaytimeLights","adaptiveLight","automaticHeadlight","steeringAssistLight","headlightHeightAdjustable","headlightCleaning","delayedHeadlightShutdown","windowAntiPinch","rearAirConditioner","rearAirOutlet","temperatureZoneControl","pm25"];
    let formDict = this.data.formDict;
    let formData = this.data.formData;

    // 初始本地有无配置字典
    let hasDisposeSel = this.data.hasDisposeSel;
    let formSelectData = this.data.formSelectData;
    for (let i = 0; i < hasDisposeDicts.length; i++) {
      formDict[hasDisposeDicts[i]] = hasDisposeSel;
      formSelectData[hasDisposeDicts[i]] = '';
      formData[hasDisposeDicts[i]] = '';
    }
    this.setData({
      formSelectData: formSelectData,
      formData: formData,
      hasDisposeDicts: hasDisposeDicts
    })

    let that = this;
    //初始化字典，后台提供字典数据
    this.loadDict(function(resultLists) {

      if (resultLists && resultLists !== null) {
        if (options.id != null) {
          wx.showLoading({
            title: '数据准备中...',
            mask: true
          })
          http.request({
            url: '/wxVehicleModel/detail',
            method: 'get',
            data: {
              id: options.id
            },
            success: (res) => {
              wx.hideLoading();

              let formSelectData = that.data.formSelectData;
              //有无配置加载数据显示
              for (let i = 0; i < hasDisposeDicts.length; i++) {

                formSelectData[hasDisposeDicts[i]] = res[hasDisposeDicts[i]] == "有" ? 1 : 0
                res[hasDisposeDicts[i]] = hasDisposeSel[formSelectData[hasDisposeDicts[i]]].code;
              }

              for (var key in res) {
                if (typeof res[key] == 'string') {
                  res[key] = res[key].replace(/&amp;|&nbsp;|\●|\○|\-/ig, '')
                  if (key == 'guidancePrice') {
                    res[key] = parseFloat(res[key])
                  }
                }


              }

              that.setData({
                formData: res,
                formSelectData: formSelectData
              });
              // 其他单选默认显示值
              for (let i = 0; i < dictFieldArray.length; i++) {
                that.dictToIndex(dictFieldArray[i], res[dictFieldArray[i]], formSelectData);
              }

            }
          });
        }
      }

    });
    this.initValidate();
    // 查看详情修改数据
  },
  //加载字典信息
  loadDict(callback) {
    var that = this,
      formData = that.data.formData

    wx.showLoading({
      title: '数据准备中...',
      mask: true
    })
    let fields = this.data.formField;

    let categoryArray = [];
    let dictFieldArray = [];
    for (let j = 0; j < fields.length; j++) {
      const rule = {};
      const message = {};
      const multiple = {};
      let formField = fields[j];
      for (let i = 0; i < formField.length; i++) {
        if (formField[i]["select"] === true && formField[i]["local"] !== true) {
          categoryArray.push(formField[i]["category"]);
          dictFieldArray.push(formField[i]["field"])
        }

      }
    }
    that.setData({
      formData: formData

    })
    getDicts(categoryArray, function(result) {

      for (let i = 0; i < categoryArray.length; i++) {
        that.handleDict(result[categoryArray[i]], dictFieldArray[i]);
      }

      wx.hideLoading()
      callback(result)
    })
  },


  // 初始化处理字典
  handleDict: function(dictList, field) {
    let formDict = this.data.formDict;
    let formData = this.data.formData;
    let formSelectData = this.data.formSelectData;
    formDict[field] = dictList;


    formData[field] = dictList[0].code;
    formSelectData[field] = 0;
    if(this.data.multipleDicts.indexOf(field) != -1){
      formData[field] = ''
    }
    this.setData({
      formDict: formDict,
      formData: formData,
      formSelectData: formSelectData
    });

  },



  saveData: function(images) {
    var that = this;
    let formData = that.data.formData;

    for (var field in formData) {
      if (formData[field] == null) {
        formData[field] = ""
      }
    }
    that.data.multipleDicts.forEach(item => {
      formData[item] = this.data.formSelectData[item]
    })
    let data = JSON.parse(JSON.stringify(formData));

    http.request({
      url: '/wxVehicleModel/save',
      data: data,
      success: (res) => {
        let pages = getCurrentPages();
        let prepage = pages[pages.length - 2];
        wx.hideLoading({});
        wx.navigateBack({
          delta: 1,
          complete: function() {
            //保存成功后，页面重新加载数据
            prepage.reloadData();
          }
        });
      },
      error: (res) => {
        wx.hideLoading({});
        $Message({
          content: "提交失败," + res.replace('ServiceException:', ''),
          type: 'error'
        });
      }
    });
  },

  // 多选选中
  bindSelectorChange: function(e) {
    let field = e.currentTarget.dataset.field;
    let formData = this.data.formData,
      formSelectData = this.data.formSelectData,
      value = e.detail.value,
      txtArr = ''
    value.forEach(item => {
      txtArr = txtArr == "" ? this.data.formDict[field][item].name : `${txtArr},${this.data.formDict[field][item].name}`
    })
    formData[field] = txtArr
    formSelectData[field] = value.join(',')
    this.setData({
      formData: formData,
      formSelectData: formSelectData
    })
  },
  // 下一步、顶部滑块
  slideTab: function() {
    let srcollWidth = this.data.srcollWidth;
    let currentStep = this.data.currentStep;
    let screenWidth = wx.getSystemInfoSync().windowWidth;
    if (currentStep === 4) {
      this.setData({
        srcollWidth: screenWidth
      })
    } else if (currentStep === 7) {
      this.setData({
        srcollWidth: screenWidth * 2
      })
    } else if (currentStep === 11) {
      this.setData({
        srcollWidth: screenWidth * 3
      })
    } else if (currentStep === 14) {
      this.setData({
        srcollWidth: screenWidth * 3 + screenWidth / 4
      })
    }
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  },
  dictToIndex: function(field, value, formSelectData) {
    let that = this,
      strCode = "",
      dict = this.data.formDict[field];

    if (value == null || value == "") {
      formSelectData[field] = 0;
      return false
    }

    if (dict != null && dict.length > 0) {
      for (var i = 0; i < dict.length; i++) {
        // 单选
        if (dict[i].name == value) {
          formSelectData[field] = i;
          that.data.formData[field] = dict[i].code
          break;
        }
        // 多选
        if (value.indexOf(dict[i].name) != -1) {
          strCode = strCode == '' ? dict[i].code : `${strCode},${dict[i].code}`
          formSelectData[field] = strCode;
        }

      }
    }
    this.setData({
      formSelectData: formSelectData,
      formData: that.data.formData
    })
  },

  // 日期选择
  bindDateChange: function(e) {
    let formData = this.data.formData;
    formData[e.currentTarget.dataset.field] = e.detail.value;
    this.setData({
      formData: formData
    });
  },

  // 单选切换
  bindDictChange: function(e) {
    let formData = this.data.formData;
    let formSelectData = this.data.formSelectData;
    let field = e.currentTarget.dataset.field;
    let index = e.detail.value;
    formSelectData[field] = index;
    formData[field] = this.data.formDict[field][index]["code"];
    if (field === "transferType" && formData[field] == 2) {
      let dict = this.data.formDict["tradeVehicleType"];
      let index = formSelectData["tradeVehicleType"];
      for (let i = 0; i < dict.length; i++) {
        if (dict[i]["code"] == "TRADE_TURN_OUT") {
          index = i;
        }
      }
      formSelectData["tradeVehicleType"] = index;
      formData["tradeVehicleType"] = "TRADE_TURN_OUT";
    }
    this.setData({
      formData: formData,
      formSelectData: formSelectData
    });
  },
  bindVal: function(e) {
    let formData = this.data.formData;
    let formSelectData = this.data.formSelectData;
    let field = e.currentTarget.dataset.field;
    let value = e.detail.value;
    if (field === "vin") {
      if (value != null && value.length > 0) {
        if (value.substr(0, 1) == 'L') {
          formData["vehicle.isImported"] = 0;
          formSelectData["vehicle.isImported"] = 0;
        } else {
          formData["vehicle.isImported"] = 1;
          formSelectData["vehicle.isImported"] = 1;
        }
      }
    }
    formData[field] = value;
    this.setData({
      formData: formData,
      formSelectData: formSelectData
    });
  },
  bindRegionChange: function(e) {
    let value = e.detail.value;
    let field = e.currentTarget.dataset.field;
    let formData = this.data.formData;
    formData[field] = value[0] + value[1];
    this.setData({
      formData: formData,
    });
  },
  //验证函数
  initValidate() {
    let fields = this.data.formField;
    let validate = [];
    for (let j = 0; j < fields.length; j++) {
      const rule = {};
      const message = {};
      let formField = fields[j];
      for (let i = 0; i < formField.length; i++) {
        rule[formField[i]["field"]] = formField[i]["rule"];
        message[formField[i]["field"]] = formField[i]["message"];
      }
      let wxValidate = new WxValidate(rule, message);
      validate.push(wxValidate);
    }
    this.WxValidate = validate;
  },
  //调用验证函数
  formSubmit: function(e) {
    const params = e.detail.value;
    //校验表单
    if (!this.WxValidate[this.data.currentStep].checkForm(params)) {
      const error = this.WxValidate[this.data.currentStep].errorList[0];
      $Message({
        content: error.msg,
        type: 'error'
      });
      return false
    }
    this.setData({
      currentStep: this.data.currentStep + 1
    });
  },
  //提交保存数据
  sumbitData: function() {
    let file = this.data.files;
    this.setData({
      show: true
    })
  },


  //弹窗确认
  handleOK: function() {
    this.setData({
      show: false,
    })
    this.saveData()
  },
  //弹窗取消
  handleCancel: function() {
    this.setData({
      show: false
    })
  },


  //上一步
  previous: function(e) {
    let srcollWidth = this.data.srcollWidth;
    let currentStep = this.data.currentStep;
    let screenWidth = wx.getSystemInfoSync().windowWidth;
    if (currentStep === 4) {
      this.setData({
        srcollWidth: 0
      })
    } else if (currentStep === 8) {
      this.setData({
        srcollWidth: screenWidth
      })
    } else if (currentStep === 12) {
      this.setData({
        srcollWidth: screenWidth * 2
      })
    } else if (currentStep === 13) {
      this.setData({
        srcollWidth: screenWidth * 3
      })
    }
    this.setData({
      currentStep: this.data.currentStep - 1
    });
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  },
  //
  handleCancel: function(e) {
    this.setData({
      show: false
    })
  },

  //chooseCity
  chooseCity: function(e) {
    let filed = e.currentTarget.dataset.field;
    let formData = this.data.formData;

    wx.navigateTo({
      url: '/pages/itemChose/index?filed=' + filed,
    })
  },
})